home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4914 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  28 lines

  1. Newsgroups: comp.lang.c
  2. Path: nntp.coast.net!torn!nott!cunews!wabakimi!jarthorn
  3. From: jarthorn@chat.carleton.ca (John Arthorne)
  4. Subject: Re: Character String --> Integer
  5. X-Nntp-Posting-Host: wabakimi.carleton.ca
  6. Message-ID: <DMFFoF.8BF@cunews.carleton.ca>
  7. Sender: news@cunews.carleton.ca (News Administrator)
  8. Organization: Carleton University
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. References: <4fb0ga$lsa@remus.rutgers.edu>
  11. Date: Wed, 7 Feb 1996 22:26:39 GMT
  12.  
  13. Force Of Nature (wempa@remus.rutgers.edu) wrote:
  14. > Is there an easy way to convert a character string such as '2425' to the
  15. > integer 2425 ???  The only way I can think of is to pick off characters 
  16. > one at a time and use switch statements to determine the value (0-9) and
  17. > then multiply by the correct power of 10.  Is there an easier way to do
  18. > this ???????
  19.  
  20. The function atoi() /* ascii-to-integer */ will convert your string to the
  21. desired integer. Supply the function with your string address and atoi()
  22. will cut off any trailing non-numeric characters and convert the rest to
  23. an integer.
  24.  
  25. John Arthorne
  26. jarthorn@chat.carleton.ca
  27.  
  28.